/*
 * @Author: Yanan Chen
 * @Date: 2021-11-02 16:08:56
 * @LastEditTime: 2021-12-07 21:25:02
 * @LastEditors: Please set LastEditors
 * @Description: 
 * @FilePath: \esp32\Src\Hal\hal_gpio.c
 * 
 */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "driver/gpio.h"
#include "hal_gpio.h"





#define GPIO_INPUT_PIN_SEL  ((1ULL<<GPIO_INPUT_IO_KEY_UP) | (1ULL<<GPIO_INPUT_IO_KEY_DOWN))
#define GPIO_OUTPUT_PIN_SEL  ((1ULL<<DIS_PIN_NUM_DC))

void gpio_init()
{
    //zero-initialize the config structure.
    gpio_config_t io_conf = {};
#if 0
    

    //disable interrupt
    io_conf.intr_type = GPIO_INTR_DISABLE;
    //set as output mode
    io_conf.mode = GPIO_MODE_OUTPUT;
    //bit mask of the pins that you want to set,e.g.GPIO18/19
    io_conf.pin_bit_mask = GPIO_OUTPUT_PIN_SEL;
    //disable pull-down mode
    io_conf.pull_down_en = 0;
    //disable pull-up mode
    io_conf.pull_up_en = 0;
    //configure GPIO with the given settings
    gpio_config(&io_conf);
#endif
    //button

    //disable interrupt
    io_conf.intr_type = GPIO_INTR_DISABLE;
    //set as output mode
    io_conf.mode = GPIO_MODE_DEF_INPUT;
    //bit mask of the pins that you want to set,e.g.GPIO18/19
    io_conf.pin_bit_mask = GPIO_INPUT_PIN_SEL;
    //disable pull-down mode
    io_conf.pull_down_en = 0;
    //disable pull-up mode
    io_conf.pull_up_en = 0;
    //configure GPIO with the given settings
    gpio_config(&io_conf);
    //sd check

    //dis dc
    //disable interrupt
    io_conf.intr_type = GPIO_INTR_DISABLE;
    //set as output mode
    io_conf.mode = GPIO_MODE_OUTPUT;
    //bit mask of the pins that you want to set,e.g.GPIO18/19
    io_conf.pin_bit_mask = GPIO_OUTPUT_PIN_SEL;
    //disable pull-down mode
    io_conf.pull_down_en = 0;
    //disable pull-up mode
    io_conf.pull_up_en = 0;
    //configure GPIO with the given settings
    gpio_config(&io_conf);
}


int gpio_read(int io)
{
   return gpio_get_level(io);
}

void gpio_write(int io,char status)
{
    gpio_set_level(io, status?(1):(0));
}
 


